package com.ruoyi.web.controller.tzzl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.tzzl.domain.WzProgramUser;
import com.ruoyi.tzzl.service.IWzProgramUserService;
import com.ruoyi.tzzl.service.IWzUserDetailsService;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户详情Controller
 * @author by caoyong
 * @date 2022/11/8
 **/
@RestController
@RequestMapping("/tzzl/details")
public class WzUserDetailsController extends BaseController {

    @Autowired
    private IWzUserDetailsService wzUserDetailsService;
    @Autowired
    private IWzProgramUserService wzProgramUserService;
    @Autowired
    private RedisCache redisCache;

    /**
     * 获取用户详情详细信息
     */
    @GetMapping("/userDetails")
    public AjaxResult getInfo(Long id)
    {
      WzProgramUser wzProgramUser = wzProgramUserService.userDetails(id);
        if (ObjectUtils.isNotEmpty(wzProgramUser)){
            wzProgramUser.setExpirationTime(redisCache.getExpire("KTHY"+wzProgramUser.getId()));
            wzProgramUser.setMatchmakerUser(wzProgramUserService.getById(wzProgramUser.getMatchmakerId()));
            return AjaxResult.success(wzProgramUser);
        }else{
            WzProgramUser user =wzProgramUserService.getById(id);
            user.setExpirationTime(redisCache.getExpire("KTHY"+user.getId()));
            user.setMatchmakerUser(wzProgramUserService.getById(user.getMatchmakerId()));
            return AjaxResult.success(user);
        }
    }

}
